#pragma once

#include <string>
#include <string.h>
#include <strings.h>
#include <arpa/inet.h>
#include <netinet/in.h>

// 封装socket和IP地址的类型
class InetAddress
{
public:
    InetAddress() = default;
    explicit InetAddress(std::string ip, uint16_t port);
    explicit InetAddress(const struct sockaddr_in& addr)
        : addr_(addr)
    {}

    std::string toIp() const;
    std::string toIpPort() const;
    uint16_t port() const;

    const sockaddr_in* getSockAddr() const {return &addr_;}
    void setSockAddr(const struct sockaddr_in& addr) { addr_ = addr; }

private:
    struct sockaddr_in addr_;
};